package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.common.R;
import com.project.service.AccessoryService;
import com.project.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Date;

@RestController
@Slf4j
@RequestMapping("/accessory")
public class AccessoryController {

    @Autowired
    private AccessoryService accessoryService;
    @Autowired
    private AliOSSUtils aliOSSUtils;
    //文件下载列表

    @GetMapping("/downloadPage")
    public R<Page> downloadPage(@RequestParam int page, @RequestParam int pageSize, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date begin, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @RequestParam  Long[] projectId){
        Page download = accessoryService.download(page, pageSize, begin, end, projectId);
        return R.success(download);

    }

    //文件下载（多选）
    @GetMapping("/download")
    public R<String> downloadAccessories(@RequestParam String[] urls) throws IOException {
        aliOSSUtils.downloads(urls);
        return R.success("下载成功");
    }

}
